
package com.kugou.game.sdk.core;

import android.os.Environment;

import com.kugou.game.sdk.utils.FileUtil;

/**
 * 系统文件夹管理
 * 
 * @author chenys
 */
public class FolderManager {

    /**
     * SD卡目录
     */
    public static final String SDCARD_PATH = Environment.getExternalStorageDirectory()
            .getAbsolutePath();

    /**
     * 应用根目录
     */
    public static final String ROOT_FOLDER = SDCARD_PATH + "/KugouPay/";

    /**
     * 用户数据目录
     */
    public static final String USER_DATA_FOLDER = ROOT_FOLDER + "UserData/";

    /**
     * 应用下载目录
     */
    public static final String APK_FOLDER = ROOT_FOLDER + "Apks/";

    /**
     * 配置目录
     */
    public static final String CONFIG_FOLDER = ROOT_FOLDER + "Config/";

    /**
     * 日志目录
     */
    public static final String LOG_FOLDER = ROOT_FOLDER + "Log/";

    /**
     * 日志文件路径
     */
    public static final String LOG_FILE_PATH = LOG_FOLDER + "log.txt";

    public static final String IMAGE_CACHE_FOLDER = ROOT_FOLDER + ".image/";

    /**
     * 用户头像
     */
    public static final String USER_HEAD_ICON = IMAGE_CACHE_FOLDER + "user_icon.png";

    /**
     * 用户数据文件后缀名
     */
    public static final String USER_DATA_FILE_EXT = ".ud";

    /**
     * 网游最新登录用户信息文件路径
     */
    public static final String CONFIG_FILE = CONFIG_FOLDER + "config.cfg";

    /**
     * 单机最新登录用户信息文件路径
     */
    public static final String CONFIG_FILE_FOR_SINGLE = CONFIG_FOLDER + "config_single.cfg";

    /**
     * 保存在本地应用目录下的最新登录信息的文件名
     */
    public static final String LAST_USER_DATA_PATH_SETTING = "last_user_path_setting";

    /**
     * 最新登录用户信息文件路径的字段名称
     */
    public static final String LAST_USER_DATA_FILE_PATH = "userDataFilePath";

    /**
     * 充值模式记录文件
     */
    public static final String RECHARGE_MODE_FILE_PATH = CONFIG_FOLDER + "recharge_mode.cfg";

    /**
     * 安全设置文件
     */
    public static final String SECURITY_SETTING_FILE_PATH = CONFIG_FOLDER + "security_setting.cfg";

    /**
     * SDK配置信息文件
     */
    public static final String PUSH_FILE_PATH = CONFIG_FOLDER + "pushsettingconfig.cfg";

    /**
     * 补丁文件下载临时保存路径
     */
    public static final String PATCH_TEMP_PATH = APK_FOLDER + "temp.jar";

    /**
     * 初始化文件系统
     */
    public static void initSystemFolder() {
        boolean isSDCardAvailable = Environment.getExternalStorageState().equals(
                Environment.MEDIA_MOUNTED);
        if (!isSDCardAvailable) {
            // 存储卡不可用，返回
            return;
        }
        checkFolder(ROOT_FOLDER);
        checkFolder(USER_DATA_FOLDER);
        checkFolder(APK_FOLDER);
        checkFolder(CONFIG_FOLDER);
        checkFolder(LOG_FOLDER);
        checkFolder(IMAGE_CACHE_FOLDER);
    }

    // 检查文件夹，不存在或文件夹版本号不同时，会重新创建
    private static void checkFolder(String folder) {
        if (!FileUtil.isFileExist(folder)) {
            FileUtil.createFolder(folder, false);
        }
    }

}
